package com.javakc.pms.dispord.service;

import com.javakc.commonutils.jpa.base.service.BaseService;
import com.javakc.commonutils.jpa.dynamic.SimpleSpecificationBuilder;
import com.javakc.pms.dispord.dao.DispOrdDao;
import com.javakc.pms.dispord.entity.DispOrd;
import com.javakc.pms.dispord.vo.DispOrdQuery;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * program:
 *
 * @author: zhangchenghui
 * @date: 2021/9/14
 * apiNote
 */
@Service
public class DispOrdService extends BaseService<DispOrdDao,DispOrd> {


    @GetMapping
    public List<DispOrd> findAll(){
        return dao.findAll();
    }

    //带分页的条件查询
    public Page<DispOrd> findPage(DispOrdQuery dispOrdQuery,int pageNo,int pageSize){
        //设置条件
        SimpleSpecificationBuilder simpleSpecificationBuilder = new SimpleSpecificationBuilder();
        if(!ObjectUtils.isEmpty(dispOrdQuery.getOrderName())){
            simpleSpecificationBuilder.and("orderName",":", dispOrdQuery.getOrderName());
        }

        return dao.findAll(simpleSpecificationBuilder.getSpecification(),PageRequest.of(pageNo-1,pageSize));
    }

}
